package pl.edu.agh.thieves.cuckoo;

import pl.edu.agh.thieves.common.Item;

import java.util.ArrayList;
import java.util.Collection;

public class Egg {
	private ArrayList<Item> items;
	
	public Egg(Collection<Item> items){
		this.items=new ArrayList<Item>();
		this.items.addAll(items);
	}
	
	public double getEggValue(){
		double value=0;
		
		for(Item item : items){
			value+=item.getValue();
		}
		
		return value;
	}
	
	public double getEggWeight(){
		double weight=0;
		
		for(Item item : items){
			weight+=item.getWeight();
		}
		
		return weight;
	}
	
	@Override
	public String toString(){
		String string="";
		
		for(Item item : items)
			string+=" weight="+item.getWeight()+" value="+item.getValue();
		
		return string;
	}
	
	public Egg getBetterEgg(Egg egg){
		if(this.getEggValue()>egg.getEggValue())
			return this;
		else
			return egg;
	}
	
	public boolean isBetter(Egg egg){
		if(this.getEggValue()>=egg.getEggValue())
			return true;
		else
			return false;
	}
	
	public Collection<Item> getItems(){
		return items;
	}
}
